﻿using Rsft.Net.DomainParser;
using Rsft.Net.DomainParser.Core.Interfaces;

namespace Service.Utity
{
    public class DomainHelper
    {
        static IDomainParser<Rsft.Net.DomainParser.Core.Entities.Service.DomainInfo> domainParser;
        static DomainHelper()
        {
            domainParser = DomainParserFactory.Create();
        }
        public static string GetRootDomain(string domain)
        {
            if (string.IsNullOrEmpty(domain))
            {
                return string.Empty;
            }
            var domainInfo = domainParser.Parse(domain);
            return $"{domainInfo.Sld}.{domainInfo.Tld}";
        }

        public static string GetSubDomain(string domain)
        {
            if (string.IsNullOrEmpty(domain))
            {
                return string.Empty;
            }
            var domainInfo = domainParser.Parse(domain);
            return domainInfo.Subdomain;
        }
    }
}
